import dash
from dash import html
import feffery_antd_components as fac
from dash.dependencies import Input, Output, ALL

app = dash.Dash(__name__)

app.layout = html.Div(
    html.Div(
        [
            fac.AntdButton(
                '打开modal',
                id='open-modal',
                type='primary'
            ),

            fac.AntdModal(
                [
                    fac.AntdForm(
                        [
                            fac.AntdAlert(
                                type='info',
                                showIcon=True,
                                message='至少一个输入框被填写，确认按钮才可点击',
                                style={
                                    'marginBottom': '10px'
                                }
                            ),
                            *[
                                fac.AntdFormItem(
                                    fac.AntdInput(
                                        id={
                                            'type': 'input-demo',
                                            'index': i
                                        },
                                        placeholder=f'输入框{i}'
                                    ),
                                    label=f'输入框{i}'
                                )
                                for i in range(5)
                            ]
                        ],
                        style={
                            'paddingTop': '25px'
                        }
                    )
                ],
                id='modal',
                renderFooter=True,
                okButtonProps={
                    'disabled': True
                }
            )
        ],
        style={
            'width': '800px',
            'margin': '0 auto'
        }
    ),
    style={
        'padding': '50px'
    }
)


@app.callback(
    Output('modal', 'visible'),
    Input('open-modal', 'nClicks')
)
def open_modal(nClicks):

    if nClicks:
        return True

    return dash.no_update


@app.callback(
    Output('modal', 'okButtonProps'),
    Input(
        {
            'type': 'input-demo',
            'index': ALL
        },
        'value'
    )
)
def set_ok_button_props(values):

    if any(values):
        return {
            'disabled': False
        }

    return {
        'disabled': True
    }


if __name__ == '__main__':
    app.run(debug=True)
